/**
 * @author:linjiye
 * @date: 2024/01/13
 * @desc: 登录模块接口定义
 **/

import {createApi} from "@reduxjs/toolkit/query/react";
import useBaseQuery from "@/hooks/useBaseQuery";

export const loginApi = createApi({
    reducerPath:'loginApi',
    baseQuery:useBaseQuery('sys'),
    endpoints(build) {
        return {
            getRandomImage:build.query({
                query:(data:any) => 'randomImage/1629428467008?t='+Date.now(),
            }),
            login:build.mutation({
                query(data) {
                    return {
                        url:'login',
                        method:"post",
                        body:data,
                        openErrMessage: true
                    }
                },
                // providesTags: ['Example']
                // transformResponse(baseQueryReturnValue, meta, arg) {
                //     return baseQueryReturnValue.data;
                // },
                // keepUnusedDataFor:0, // 设置数据缓存的时间，单位秒 默认60s
            }),
            // toAgentRedirect: build.mutation({
            //     query(data) {
            //         return {
            //             url:'openApi/AgentChat/toAgentRedirect',
            //             method:"post",
            //             data:data
            //         }
            //     },
            //     transformResponse(baseQueryReturnValue, meta, arg) {
            //         return baseQueryReturnValue.data;
            //     },
            // })
            getDeptTreeList:build.query({
                query:(data:any) => {
                  return {
                    url: 'sysDepart/queryMyDeptTreeListByScrm',
                    method:"get",
                    params:data,
                    openErrMessage: true
                  }
                },
            }),
            getOssInfo:build.mutation({
                query:(data:any) => {
                  return {
                    url: 'common/ossAccessInfo/chat',
                    method:"get",
                    params:data,
                    openErrMessage: true
                  }
                },
            }),
            getUserInfo:build.mutation({
                query:(data:any) => {
                  return {
                    url: 'user/getUserInfo',
                    method:"get",
                    params:data,
                    openErrMessage: true
                  }
                },
            }),
            getNoticeList: build.query({
              query(data) {
                return {
                  url:'annountCement/vue3List/app/list',
                  method:"get",
                  params: data,
                  openErrMessage: true
                }
              },
            }),
        }
    }
});

export const {
    useGetRandomImageQuery,
    useLoginMutation,
    useGetDeptTreeListQuery,
    useGetOssInfoMutation,
    useGetUserInfoMutation,
    useGetNoticeListQuery,
} = loginApi;
